package com.zhangpeng520.register.controller;

import com.zhangpeng520.common.security.SecurityUtils;
import com.zhangpeng520.register.service.RegisterService;
import com.zhangpeng520.user.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2017/8/9 0009.
 */
@Controller
@RequestMapping("register")
public class RegisterController {

    @Autowired
   private RegisterService registerService;


    /**
     *
     *@Author zhangpeng(www.zhangpeng520.com)
     *@Date 2017/8/9 0009 16:16
     *@Desripition 用户注册
     *
     */
    @RequestMapping
    public String register()
    {

        return "register";
    }

    /**
     *
     *@Author zhangpeng(www.zhangpeng520.com)
     *@Date 2017/8/10 0010 11:14
     *@Desripition 注册成功后跳转到登录页
     *
     */
    @ResponseBody
    @RequestMapping("/check")
    public String index(HttpServletRequest request) throws Exception
    {
        String username=request.getParameter("username");
        String password=SecurityUtils.encryptPassword(request.getParameter("password"));
        String mobile=request.getParameter("mobile");
        String realname=request.getParameter("realname");
        User user=new User();
        user.setUsername(username);
        user.setPassword(password);
        user.setRealName(realname);
        user.setMobile(mobile);
       int number= registerService.createUser(user);
       if(number==-520)
       {
           return "register_fail";
       }
       else
       {
           return "register_success";
       }

    }
}
